//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __CKERNEL_H__
#define __CKERNEL_H__

#define _NO_INCLIST
#include <elasys_server.h>

class CKernel : public IKernel
{
// Interface functions
//
public:
    CARAPI_(PInterface) Probe(
        /* [in]  */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Aggregate(
        /* [in] */ AggrType aggrType,
        /* [in] */ IInterface* pObject);

    CARAPI GetDomain(
        /* [out] */ IInterface** ppObject);

    CARAPI GetSystemTime(
        /* [out] */ SystemTime *pTime);

    CARAPI SetSystemTime(
        /* [in] */ SystemTime time);

    CARAPI GetElapsedTime(
        /* [out] */ Millisecond32 *pTime);

    CARAPI GetIdleTime(
        /* [out] */ Millisecond32 *pTime);

    CARAPI CreateProcess(
        /* [out] */ IProcess **ppProcess);

    CARAPI  GetCurrentProcess(
        /* [out] */ IProcess **ppProcess);

    CARAPI GetAllProcesses(
        /* [out] */ IObjectEnumerator **ppProcesses);

    CARAPI ExitProcess(
        /* [in] */ Int32 exitCode);

    CARAPI CreateThread(
        /* [in] */ Address threadMainStartup,
        /* [in] */ Address threadRoutine,
        /* [in] */ Address threadArg,
        /* [in] */ ThreadCreationFlags flags,
        /* [out] */ IThread **ppThread);

    CARAPI GetCurrentThread(
        /* [out] */ IThread **ppThread);

    CARAPI LoadModule(
        /* [in] */ WString wsName,
        /* [in] */ ModuleLoadFlags flags,
        /* [out] */ BufferOf<Address> * pDllMainStartups,
        /* [out] */ IModule **ppMod,
        /* [out] */ Boolean *pNewlyLoaded);

    CARAPI Sleep(
        /* [in] */ Millisecond32 period,
        /* [out] */ WaitResult *pResult);

    CARAPI GetDelayFactor(
        /* [out] */ Int32 *pLoopCount);

    CARAPI  Yield();

    CARAPI  VirtualMemoryMap(
        /* [in] */ Address startingAddr,
        /* [in] */ MemorySize size,
        /* [in] */ MemoryMapFlags flags,
        /* [in] */ MemoryProtection protect,
        /* [out] */ Address *pSettledAddr);

    CARAPI MemoryQuery(
        /* [in] */ Address address,
        /* [out] */ Address *pBaseAddr,
        /* [out] */ MemorySize *pSize);

    CARAPI MemoryQueryPhysicalBlock(
        /* [in] */ Address address,
        /* [out] */ Address *pPhysicalBaseAddr,
        /* [out] */ MemorySize *size);

    CARAPI MemoryProtect(
        /* [in] */ Address baseAddr,
        /* [in] */ MemorySize size,
        /* [in] */ MemoryProtection protect);

    CARAPI MemoryCheck(
        /* [in] */ Address address,
        /* [in] */ MemoryProtection protect,
        /* [out] */ Boolean *pValid);

    CARAPI  MemoryCommit(
        /* [in] */ Address address);

    CARAPI  IoRemap(
        /* [in] */ Address startingAddr,
        /* [in] */ MemorySize size,
        /* [in] */ Address physicalAddr,
        /* [in] */ MemoryMapFlags flags,
        /* [in] */ Int32 protect,
        /* [out] */ Address *pSettledAddr);

    CARAPI MemoryUnmap(
        /* [in] */ Address baseAddr,
        /* [in] */ MemorySize size);

    CARAPI CreateMutex(
        /* [out] */ IMutex **ppMutex);

    CARAPI CreateNamedMutex(
        /* [in] */ WString name,
        /* [out] */ IMutex **ppMutex,
        /* [out] */ Boolean *pAlreadyExists);

    CARAPI CreateCondition(
        /* [out] */ ICondition **ppCondition);

    CARAPI CreateNamedCondition(
        /* [in] */ WString name,
        /* [out] */ ICondition **ppCondition,
        /* [out] */ Boolean *pAlreadyExists);

    CARAPI CreateEvent(
        /* [in] */ Boolean manualReset,
        /* [in] */ EventState initialState,
        /* [out] */ IEvent **ppEvent);

    CARAPI CreateNamedEvent(
        /* [in] */ WString name,
        /* [in] */ Boolean manualReset,
        /* [in] */ EventState initialState,
        /* [out] */ IEvent **ppEvent,
        /* [out] */ Boolean *pAlreadyExists);

    CARAPI CreateReaderWriterLock(
        /* [out] */ IReaderWriterLock **ppRWLock);

    CARAPI CreateNamedReaderWriterLock(
        /* [in] */ WString name,
        /* [out] */ IReaderWriterLock **ppRWLock,
        /* [out] */ Boolean *pAlreadyExists);

    CARAPI CreateSharedMemory(
        /* [in] */ MemorySize nSize,
        /* [in] */ Boolean commit,
        /* [out] */ ISharedMemory **ppSharedMemory);

    CARAPI CreateNamedSharedMemory(
        /* [in] */ WString name,
        /* [in] */ MemorySize nSize,
        /* [in] */ Boolean commit,
        /* [out] */ ISharedMemory **ppSharedMemory,
        /* [out] */ Boolean *pAlreadyExists);

    CARAPI RequestSystemEvent(
        /* [in] */ SystemEvents interestedEvents,
        /* [out] */ IEvent **ppEvent);

    CARAPI GetHostingManager(
        /* [out] */ IHostingManager** ppManager);

    CARAPI GetEnvironmentMutex(
        /* [out] */ IMutex **ppEnvMutex);

    CARAPI AcquireThreadLocalSlot(
        /* [in] */ ThreadLocalSlotType slotType,
        /* [out] */ Int32 *pSlotIndex);

    CARAPI RelinquishThreadLocalSlot(
        /* [in] */ Int32 slotIndex,
        /* [out] */ BufferOf<Address> * pUsedPtrs);

    CARAPI CleanUpThreadLocalSlot(
        /* [in] */ Int32 slotIndex,
        /* [out] */ BufferOf<Address> * pUsedPtrs);

    CARAPI WaitForAnyEvents(
        /* [in] */ const BufferOf<IEvent *> & events,
        /* [out] */ WaitResult *pResult,
        /* [out] */ Int32 *pIndex,
        /* [out] */ EventState *pState);

    CARAPI TryWaitForAnyEvents(
        /* [in] */ const BufferOf<IEvent *> & events,
        /* [in] */ Millisecond32 timeout,
        /* [out] */ WaitResult *pResult,
        /* [out] */ Int32 *pIndex,
        /* [out] */ EventState *pState);

    CARAPI GetGlobalMemorySizes(
        /* [out] */ MemorySize *pTotalPhysicalMemorySize,
        /* [out] */ MemorySize *pAvailablePhysicalMemorySize);

    CARAPI FlushInstructionCache(
        /* [in] */ Address base,
        /* [in] */ MemorySize size);
};

#endif // __CKERNEL_H__
